package com.handpay.nocardpay.baselibrary.pay.uniopayquick.presenter;

import android.content.Context;

import com.handpay.nocardpay.baselibrary.commbase.model.IBaseModel;
import com.handpay.nocardpay.baselibrary.commbase.model.bean.BaseErrorInfo;
import com.handpay.nocardpay.baselibrary.commbase.presenter.IBasePresenter;
import com.handpay.nocardpay.baselibrary.pay.uniopayquick.model.IUnionPayModel;
import com.handpay.nocardpay.baselibrary.pay.uniopayquick.model.bean.UnionQuickPayRespBean;
import com.handpay.nocardpay.baselibrary.pay.uniopayquick.model.impl.UnionPayModelImpl;
import com.handpay.nocardpay.baselibrary.pay.uniopayquick.view.IUniopayquickView;

import java.util.HashMap;


public class UnionPayQuickPresenter implements IBasePresenter {
    private IUniopayquickView iUniopayquickView;
    private IUnionPayModel<UnionQuickPayRespBean> mUnionPayModel;


    public void setiUniopayquickView(IUniopayquickView iUniopayquickView) {
        this.iUniopayquickView = iUniopayquickView;
    }

    public UnionPayQuickPresenter(Context mContext) {
        mUnionPayModel = new UnionPayModelImpl(mContext);
    }

    public void quickUnioPay(HashMap<String, Object> paramers, boolean isShowLoading) {
        if (iUniopayquickView != null) {
            if (isShowLoading) {
                iUniopayquickView.showProgress();
            }
        }
        mUnionPayModel.quickPayment(UnionQuickPayRespBean.class, paramers, new IBaseModel.OnRequestFinishedListener<UnionQuickPayRespBean>() {
            @Override
            public void onError(BaseErrorInfo baseErrorInfo) {
                if (iUniopayquickView != null) {
                    iUniopayquickView.hideProgress();
                    iUniopayquickView.showErrorAlert(baseErrorInfo);
                }
            }

            @Override
            public void onSuccess(UnionQuickPayRespBean response) {
                if (iUniopayquickView != null) {
                    iUniopayquickView.hideProgress();
                    iUniopayquickView.getPaymentResult(response);
                }
            }
        });
    }


    @Override
    public void onDestory() {
        if (iUniopayquickView != null) {
            iUniopayquickView = null;
        }
    }
}
